<?php
/**
 * Created by PhpStorm.
 * User: Hello pan
 * Date: 9/14/25
 * Time: 11:36 AM
 */

namespace app\services;

use yii\base\Component;
use yii\base\InvalidConfigException;

class Application extends Component
{
    public $childService = [
        'log' => 'app\services\LogService',
    ];

    // 一实例化的
    protected $_childService = [];

    /**
     * Desc: 获取子服务
     * Auth: hello pan
     * Date: 9/14/25 11:50 AM
     * @param $className
     * @return mixed|object
     * @throws InvalidConfigException
     */
    protected function getChildService($className)
    {
        if(!isset($this->_childService[$className])){
            if(isset($this->childService[$className])){
                $this->_childService[$className] = \Yii::createObject($this->childService[$className]);
            }else{
                throw new InvalidConfigException('没有配置该类');
            }
        }
        return $this->_childService[$className];
    }


    /**
     * Desc: 获取子服务
     * Auth: hello pan
     * Date: 9/14/25 11:50 AM
     * @param $name
     * @return mixed
     */
    public function __get($name)
    {
        return $this->getChildService($name);
    }
}